package com.syni.mdd.yhd.common.all.service.impl;

import com.syni.mdd.sjb.common.component.utils.common.utils.ParamsMap;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.constants.ResultMsg;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsBusinessComplainDao;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsBusinessComplain;
import com.syni.mdd.yhd.common.all.entity.BmsVideo;
import com.syni.mdd.yhd.common.all.service.BmsBusinessComplainService;
import com.syni.mdd.yhd.common.all.service.BmsBusinessService;
import com.syni.mdd.yhd.common.all.service.BmsCommonService;
import com.syni.mdd.yhd.common.all.service.BmsVideoService;
import com.syni.mdd.yhd.common.all.service.search.BmsSearchService;
import com.syni.mdd.yhd.common.all.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @className
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class BmsBusinessComplainServiceImpl implements BmsBusinessComplainService {
    @Autowired
    BmsBusinessComplainDao bmsBusinessComplainDao;

    @Override
    public BmsBusinessComplainDao getBaseDao() {
        return bmsBusinessComplainDao;
    }

    @Override
    public Map<String, Object> getToken(ParamsMap paramsMap) {
        final String getTokenUrl = "https://openapi.esign.cn/v1/oauth2/access_token";
        Map<String,Object> params = new HashMap<>();
        params.put("appId",Constants.FLOW_APP_ID);
        params.put("secret",Constants.FLOW_APP_SECRET);
        params.put("grantType","client_credentials");
        String responseBody = RestTemplateUtils.getForEntity(getTokenUrl,params);

        return null;
    }

    @Override
    public Map<String, Object> complain(ParamsMap paramsMap) {
        Integer userId = paramsMap.getInteger("userIdentify");
        Integer businessId = paramsMap.getInteger("businessId");
        Integer complainType = paramsMap.getInteger("complainType");
        String remark = paramsMap.getString("remark");
        BmsBusinessComplain bmsBusinessComplain = new BmsBusinessComplain();
        bmsBusinessComplain.setBusinessId(businessId);
        bmsBusinessComplain.setComplainType(complainType);
        bmsBusinessComplain.setRemark(remark);
        bmsBusinessComplain.setNewTime(new Date());
        bmsBusinessComplain.setUserId(userId);
        bmsBusinessComplainDao.save(bmsBusinessComplain);
        return ResultMapHelper.success(bmsBusinessComplain,ResultMsg.HAND_SUCCESS);
    }
}
